home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Programming / tek / array / stringcopystrn.c < prev    next >
C/C++ Source or Header  |  2001-05-12  |  577b  |  35 lines

  1.  
  2. #include "tek/array.h"
  3.  
  4. /* 
  5. **    TEKlib
  6. **    (C) 2001 TEK neoscientists
  7. **    all rights reserved.
  8. **
  9. **    TBOOL TStringCopyStrN(TSTRPTR *s1, TSTRPTR s2, TUINT32 n)
  10. **
  11. **    copy max. n characters of regular string to a dynamic string
  12. **
  13. */
  14.  
  15. TBOOL TStringCopyStrN(TSTRPTR *s1, TSTRPTR s2, TUINT n)
  16. {
  17.     if (*s1)
  18.     {
  19.         TARRAY *a1 = *((TARRAY **) s1) - 1;
  20.  
  21.         if (a1->valid)
  22.         {
  23.             TUINT newlen = TStrLen(s2);
  24.             newlen = TMIN(newlen, n);
  25.             if (TArraySetLen((TAPTR *) s1, newlen + 1))
  26.             {
  27.                 TMemCopy(s2, *s1, newlen);
  28.                 (*s1)[newlen] = 0;
  29.                 return TTRUE;    
  30.             }
  31.         }
  32.     }
  33.     return TFALSE;
  34. }
  35.